/* const express = require('express')

const app = express()

app.use((req,res,next)=>{
    req.a = '我是请求a'
    console.log('midware1')
    next()
})

app.use((req,res,next)=>{
    req.b = '我是请求b'
    console.log('midware2')
    next()
})

app.get('/',(req,res)=>{
    res.send({
        msg:'midware learning',
        // 数据共享 向下传递
        a: req.a,
        bb: req.b,
    })
})

app.listen(8080,()=>{
    console.log('8080 running')
}) */

/* const express = require('express')
const app = express()

app.use((req,res,next)=>{
    req.a = '我是请求a'
    console.log('midware1')
    next()
})

app.use((req,res,next)=>{
    req.b = '我是请求b'
    console.log('midware2')
    next()
})

app.get('/',(req,res)=>{
    res.send({
        msg:'midware learning',
        a: req.a,
        b: req.b,
    })
})

app.listen(8080,()=>{
    console.log('8080 running')
}) */

const express = require('express')
const app = express()

app.use((req,res,next)=>{
    req.a = '我是请求a';
    console.log(req.a)
    next()
})

app.use((req,res,next)=> {
    req.b = '我是请求b';
    console.log(req.b)
    next()
})

app.get('/',(req,res)=>{
    res.send({
        msg: `express`,
        a: req.a,
        b: req.b
    })
})

app.listen(8080,()=>{
    console.log('8080 running')
})